package com.guoxue.dao.impl;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.guoxue.dao.ICollectAndTransferDao;
import com.guoxue.domain.CollectAndTransferVo;
@Repository
public class CollectAndTransferImpl extends BaseDaoImpl<CollectAndTransferVo> implements ICollectAndTransferDao{
	
	@Override
	public void saveCollectAndTransfer(CollectAndTransferVo ct) {
		saveOrUpdate(ct);
	}
	
	@Override
	public List<CollectAndTransferVo> getCollectAndTransferList() {
		return find("FROM CollectAndTransferVo");
	}
	
	@Override
	public void deleteCollectAndTransfer(int id,Integer uid) {
		executeHql("DELETE FROM CollectAndTransferVo c WHERE c.id=? AND c.uid = ? AND sysflag = 0", new Object[] {id,uid});
	}

	@Override
	public Long getCollectAndTransferTotal(int uid,int type,String tapesId) {
		return count("SELECT count(*) FROM CollectAndTransferVo c WHERE c.uid = ? AND c.type = ? AND c.tapeId = ? AND sysflag = 0",new Object[] {uid,type,tapesId});
	}
	
	@Override
	public CollectAndTransferVo getCollectAndTransfer(int  id,Integer uid) {
		return get("FROM CollectAndTransferVo c WHERE c.id = ? AND c.uid = ? AND sysflag = 0", new Object[] {id,uid});
	}

	@Override
	public List<CollectAndTransferVo> getCollectAndTransferList(Integer uid, Integer type) {
		return find("FROM CollectAndTransferVo c WHERE c.uid = ? AND c.type = ? AND sysflag = 0",new Object[] {uid,type});
	}

	@Override
	public Long getCollectAndTransferTotal(Integer uid, String tapesUid, Integer type, String tapesId) {
		return count("SELECT count(*) FROM CollectAndTransferVo c WHERE c.uid = ? AND c.tapesUid = ? AND c.type = ? AND c.tapeId = ? AND sysflag = 0 AND c.tapesUid != ?",new Object[] {uid,tapesUid,type,tapesId,String.valueOf(uid)});
	}

	@Override
	public Long getMyCollectAndTransferTotal(Integer uid, int type) {
		return count("SELECT count(*) FROM CollectAndTransferVo c WHERE c.uid = ? AND c.type = ? AND sysflag = 0 AND c.tapesUid != ?",new Object[] {uid,type,String.valueOf(uid)});
	}

	@Override
	public List<CollectAndTransferVo> getCollectAndTransferList(Integer uid, Integer type, Integer start,Integer totalCount) {
		return find("FROM CollectAndTransferVo c WHERE c.uid = ? AND c.type = ? AND sysflag = 0 AND c.tapesUid != ? ORDER BY c.commitTime DESC",new Object[] {uid,type,String.valueOf(uid)},++start,totalCount);
	}

	@Override
	public List<CollectAndTransferVo> getCollectAndTransferList(Integer userId, Integer type, Integer start,
			Integer totalCount, String date) {
		return find("FROM CollectAndTransferVo c WHERE c.uid = ? AND c.type = ? AND sysflag = 0 AND c.tapesUid != ? AND c.commitTime <= ? ORDER BY c.commitTime DESC",new Object[] {userId,type,String.valueOf(userId),date},++start,totalCount);
	}
	
}
